<?php

namespace Modules\Product\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

// use Illuminate\Notifications\Messages\NexmoMessage;
use Modules\Core\Channels\MiniappSubscribeMessageChannel;

use Miniapp;
use Setting;

class PresellStart extends Notification
{
    use Queueable;

    public $product;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($product)
    {
        $this->product = $product;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param mixed $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        $channels = [
            MiniappSubscribeMessageChannel::class
        ];

        return $channels;
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param mixed $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
                    ->line('The introduction to the notification.')
                    ->action('Notification Action', 'https://laravel.com')
                    ->line('Thank you for using our application!');
    }

    /**
     * 获取通知的 Nexmo / 短信展示方式
     *
     * @param  mixed  $notifiable
     * @return NexmoMessage
     */
    public function toNexmo($notifiable)
    {
        return (new NexmoMessage)
        ->content('Your SMS message content');
    }

    /**
     * Get the array representation of the notification.
     *
     * @param mixed $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }

    /**
     * 获取通知的模板消息
     *
     * @param  mixed  $notifiable
     * @return VoiceMessage
     */
    public function toMiniappSubscribeMessage($notifiable)
    {
        $product = $this->product;
        $page = 'pages/productDetail/index?uuid=' . $product->uuid;

        // $paidAt = $order->money_paid_at ?: $order->score_paid_at;

        // $payPrice = '0元';
        // if ($order->pay_money_price) {
        //     $payPrice = $order->pay_price / 100 . '元';
        // }

        // $coinPrice = '无';
        // if ($order->pay_score_price) {
        //     $coinPrice = '使用' . $order->pay_score_price . (@Setting::get('sys_score')['alias'] ?: '积分') . '支付';
        // }

        $message = [
            'page' => $page,
            'data' => [
                'thing1' => [
                    'value' => $product->title
                ],
                'time2' => [
                    'value' => $product->presell_date
                ],
                'thing4' => [
                    'value' => '亲，您关注的商品1分钟后就要开售了哦~'
                ]
            ],
        ];

        $miniapp = Miniapp::get('default');

        return [
            $miniapp,
            'presell_start',
            $message
        ];
    }
}
